var main = (function(e){

    e.updateList = function (){
        dataBase.getClientsList( function(result){
           var i, num = result.length, str=[];
            for(i=0;i<num;i+=1){
                str.push("<li clientID='" + result[i].ClientID + "'><a  style='display: inline-block; padding: 14px 14px 0px 14px;; font-size: 14px;'>" +
                            result[i].Name + "</a><span name='Time' style='font-size: 10px; padding-left: 14px; " +
                            "padding-bottom: 14px; display: block;' timeZone='" + result[i].TimeZone + "'>Current date: " +
                            helper.timeToString(result[i].TimeZone) + "</span></li>")
            }
            if(result.length>0)
                $("#lstClients").html(str.join('')).listview('refresh');
        });
    };

    function ResetClocks(){
        var clocks = $("span[name='Time']");
        for(var i=0;i<clocks.length;i+=1){
            clocks.eq(i).html("Current date: " + helper.timeToString(parseInt(clocks.attr("timeZone"))));
        }
    }

    e.init = function (){
        $("#lstClients").delegate("li", "click", function () {
            cID = parseInt($(this).attr("clientID"));
            client.loadClient(cID);
            $.mobile.changePage("#pnClient");
            //windows.showPage("pnMainPage","pnClient");
        });
        e.updateList();
        setInterval(function(){
            var clocks = $("span[name='Time']");
            for(var i=0;i<clocks.length;i+=1){
                clocks.eq(i).html("Current date: " + helper.timeToString(parseInt(clocks.eq(i).attr("timeZone"))));
            }
        },60000);
        $("#btnShowAddNewClient").click( function (){
            addnewclient.initAddnewclient();
            $.mobile.changePage("#pnAddNewClient");
        });
    };
    e.init();
    return e;
}(main || {}));
